/*
 *
 *  * Copyright 2015-2101 Shouqi Limousine & chauffeur Group.
 *  *
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  *
 *  *      http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 *
 */

package com.sq.plugins.redis.sentinel;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author wangliang
 */
public class RedisSentinelPoolConfig {
    /**
     * 默认最大活跃连接数  8
     */
    private static final int DEFAULT_MAX_TOTAL = 8;

    /**
     * 最大闲置数量 8
     */
    private static final int DEFAULT_MAX_IDLE = 8;

    /**
     * 最小闲置数量 0
     */
    private static final int DEFAULT_MIN_IDLE = 0;

    /**
     * beanName
     */
    private String poolName;
    /**
     * Name of Redis server.
     */
    private String master;

    /**
     * 节点地址 host:port,host:port
     */
    private String nodes;

    /**
     * 最大活跃连接数
     */
    private int maxTotal = DEFAULT_MAX_TOTAL;

    /**
     * 最大闲置数量
     */
    private int maxIdle = DEFAULT_MAX_IDLE;

    /**
     * 最小闲置数量
     */
    private int minIdle = DEFAULT_MIN_IDLE;

    /**
     * 连接超时时间
     */
    protected int connectionTimeout = 2000;

    /**
     * 读取数据超时
     */
    protected int soTimeout = 2000;

    /**
     * 密码
     */
    protected String password;

    /**
     * 数据库
     */
    protected int database = 0;

    /**
     * 客户端名称
     */
    protected String clientName;

    public Set<String> getHostAndPorts(){
        return new HashSet<>(Arrays.asList(nodes.split(",")));
    }

    public String getPoolName() {
        return poolName;
    }

    public void setPoolName(String poolName) {
        this.poolName = poolName;
    }

    public String getMaster() {
        return master;
    }

    public void setMaster(String master) {
        this.master = master;
    }

    public String getNodes() {
        return nodes;
    }

    public void setNodes(String nodes) {
        this.nodes = nodes;
    }

    public int getMaxTotal() {
        return maxTotal;
    }

    public void setMaxTotal(int maxTotal) {
        this.maxTotal = maxTotal;
    }

    public int getMaxIdle() {
        return maxIdle;
    }

    public void setMaxIdle(int maxIdle) {
        this.maxIdle = maxIdle;
    }

    public int getMinIdle() {
        return minIdle;
    }

    public void setMinIdle(int minIdle) {
        this.minIdle = minIdle;
    }

    public int getConnectionTimeout() {
        return connectionTimeout;
    }

    public void setConnectionTimeout(int connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public int getSoTimeout() {
        return soTimeout;
    }

    public void setSoTimeout(int soTimeout) {
        this.soTimeout = soTimeout;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getDatabase() {
        return database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public String getClientName() {
        return clientName;
    }

    public void setClientName(String clientName) {
        this.clientName = clientName;
    }
}
